package com.shaoyu.tools.testcase.controller;


import com.shaoyu.spring.study.validate.annotation.ValidateFor;
import com.shaoyu.spring.study.validate.annotation.ValidateIntercept;
import com.shaoyu.spring.study.validate.annotation.ValidateInterceptMethod;
import com.shaoyu.spring.study.validate.core.ValidateContext;

/**
 * @Desc :
 * @Author: shaoyu
 * @Date : 2022/8/23 11:10
 */
@ValidateIntercept
public class TestControllerInterceptor {


    @ValidateFor("com.shaoyu.tools.testcase.controller.TestController#testValidate")
    @ValidateInterceptMethod(value = {"validateP1","validateP2","switch"},alias = {"p1:p3"})
    public Long testValidate(){
        return null;
    }

    @ValidateFor("validateP1")
    public Long validateP1(Long p3){
        if(p3 == 99L){
            ValidateContext.passMandatory();
            return null;
        }
        if(p3>9999){
            ValidateContext.getCurrentContext().set("checkResult","p1参数有敏感词");
//            return "p1参数有敏感词";
        }
        return null;
    }
    @ValidateFor("validateP1")
    public Long validateP11(Long p1){
        if(p1>500){
            return 1111111L;
        }
        return null;
    }
    @ValidateFor("validateP2")
    public Long validateP2(Long p2){
        if(p2>100){
            return 111111111L;
        }
        return null;
    }

    @ValidateFor("switch")
    public Long testSwitch(){
        return Math.random()>0.5?11111111111L:22222222L;
    }
}
